<template>
  <el-submenu v-if="item.children && item.children.length > 0" :index="item.url || `/${item.code}`">
    <template slot="title">
      <div class="menu-icon"><i :class="item.img" /></div>
      <span slot="title">{{ item.name }}</span>
    </template>
    <sidebar-item v-for="child in item.children" :item="child" :key="`/${item.code}/${child.code}`" />
  </el-submenu>
  <el-menu-item v-else :index="item.url || `/${item.code}`">
    <div class="menu-icon"><i :class="item.img" /></div>
    <span slot="title">{{ item.name }}</span>
  </el-menu-item>
</template>
<script>
export default {
  name: 'SidebarItem',
  props: {
    item: {
      type: Object,
      required: true,
    },
  },
};
</script>

<style lang="less" scoped>
.menu-icon {
  width: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  img {
    width: 18px;
  }
}
</style>
